package com.xszx.servlet;

import com.xszx.beans.Goods;
import com.xszx.beans.Orders;
import com.xszx.beans.dto.OrdersDto;
import com.xszx.dao.GoodsDao;
import com.xszx.dao.OrdersDao;
import com.xszx.dao.impl.GoodsDaoImpl;
import com.xszx.dao.impl.OrdersDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/SelectOrdersServlet")
public class SelectOrdersServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        String name = req.getParameter("name");
        String state = req.getParameter("selectState");
        int selectState = -1;
        if (state != null) {
            selectState = Integer.parseInt(state);
        }

        OrdersDao ordersDao = new OrdersDaoImpl();
        List<OrdersDto> orders = ordersDao.selectOrders(name, selectState);

        req.setAttribute("name", name);
        req.setAttribute("selectState", state);

        req.setAttribute("orders", orders);
        req.getRequestDispatcher("my_likafu/orders.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
